//
//  LLYAddViewController.m
//  ZZ15091031LiuLeiYan
//
//  Created by qianfeng001 on 15/8/28.
//  Copyright (c) 2015年 刘雷岩. All rights reserved.
//

#import "LLYAddViewController.h"


@interface LLYAddViewController ()
{
    UITextField *_nameTextField;
    UITextField *_ageTextField;
}

@end

@implementation LLYAddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createUI];
    [self createTapGesture];
}

- (void)createTapGesture {
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
    [self.view addGestureRecognizer:tap];
}

- (void)hideKeyboard {
    [self.view endEditing:YES];
}

- (void)createUI {
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 100, 50, 30)];
    nameLabel.text = @"姓名";
    nameLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:nameLabel];
    
    UILabel *ageLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 170, 50, 30)];
    ageLabel.text = @"年龄";
    ageLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:ageLabel];
    
    _nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 100, 200, 30)];
//    _nameTextField.placeholder = @"请输入姓名";
    _nameTextField.borderStyle = UITextBorderStyleRoundedRect;
    
    [self.view addSubview:_nameTextField];
    
    _ageTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 170, 200, 30)];
//    _ageTextField.placeholder = @"请输入姓名";
    _ageTextField.borderStyle = UITextBorderStyleRoundedRect;
    _ageTextField.keyboardType = UIKeyboardTypeNumberPad;
    
    [self.view addSubview:_ageTextField];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"返回" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    button.frame = CGRectMake(140, 230, 50, 30);
    [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button];
}

- (void)back {
    if ([_nameTextField.text compare:@""] == NSOrderedSame && [_ageTextField.text compare:@""] == NSOrderedSame) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"警告" message:@"您木有输入内容" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        [alertView show];
        return ;
    }else {
    
        if (self.block) {
            self.block(_nameTextField.text,_ageTextField.text);
        }
    
        [self.view endEditing:YES];
        [self dismissViewControllerAnimated:YES completion:^{
        
        }];
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
